/**
 * EntityDao.java
 * com.opsys.api.common.dao
 *
 * Function：(一句话功能说明) 
 *
 *  version      date      		  author
 * ──────────────────────────────────────
 *  Ver 1.0  2013-11-4    CWL
 *
 * Copyright(c) 2013, PUKKA All Rights Reserved.
*/

package com.zhehekeji.opsys.api.common.dao;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;


/**
 * (一句话功能说明)
 *
 * @author   CWL
 * @version  1.0
 * @see
 * @since    1.0
 * @Date	2013-11-4   下午5:26:16
 */
public  interface EntityDao {

	/**
	 * 
	 * 查询
	 *
	 * @param entityClass 实体类
	 * @param entityid 对象id
	 * @return
	 */
	<T> T get(Class<T> entityClass, Object entityid) throws SQLException;
	
	/**
	 * 
	 * 查询
	 *
	 * @param entityClass 实体类
	 * @param entityid 对象id
	 * @return
	 */
	<T> T get(Class<T> entityClass, String wherejpql,Object[] queryParams) throws SQLException;
	
	/**
	 * 获取分页数据    排序，条件
	 * @param <T>
	 * @param entityClass 实体类
	 * @param firstindex 开始索引
	 * @param maxresult 需要获取的记录数
	 * @param wherejpql o.visible=?1 and o.xxx like ?2
	 * @param queryParams {0,xxx,...}
	 * @param orderby  key 存放实体属性，value存放ASC/DESC
	 * @return
	 */
	/**
	 * order by key1 desc,key2 asc,xxx desc
	 * LinkedHashMap  按添加的先后顺序，在内部不重排序，HashMap  在内部还可能会排序
	 */
	<T> List<T> getScrollData(Class<T> entityClass,int firstindex,int maxresult,
			String wherejpql,Object[] queryParams,LinkedHashMap<String, String> orderby) throws SQLException;
	/**
	 * 获取分页数据    条件
	 * @param <T>
	 * @param entityClass 实体类
	 * @param firstindex 开始索引
	 * @param maxresult 需要获取的记录数
	 * @param wherejpql o.visible=?1 and o.xxx like ?2
	 * @param queryParams {0,xxx,...}
	 * @return
	 */
	<T> List<T> getScrollData(Class<T> entityClass,int firstindex,int maxresult,
			String wherejpql,Object[] queryParams) throws SQLException;
	
	/**
	 * 获取分页数据   排序
	 * @param <T>
	 * @param entityClass 实体类
	 * @param firstindex 开始索引
	 * @param maxresult 需要获取的记录数
	 * @param orderby key 存放实体属性，value存放ASC/DESC
	 * @return
	 */
	<T> List<T> getScrollData(Class<T> entityClass,int firstindex,int maxresult,
			LinkedHashMap<String, String> orderby) throws SQLException;
	
	/**
	 * 获取分页数据  
	 * @param <T>
	 * @param entityClass 实体类
	 * @param firstindex 开始索引
	 * @param maxresult 需要获取的记录数
	 * @return
	 */
	<T> List<T> getScrollData(Class<T> entityClass,int firstindex,int maxresult) throws SQLException;
	
	/**
	 * 获取数据
	 * @param <T>
	 * @param entityClass 实体类
	 * @param wherejpql o.visible=?1 and o.xxx like ?2
	 * @param queryParams {0,xxx,...}
	 * @return
	 */
	<T> List<T> getScrollData(Class<T> entityClass,String wherejpql,Object[] queryParams) throws SQLException;
	/**
	 * 获取数据   
	 * @param <T>
	 * @param entityClass 实体类
	 * @return
	 */
	<T> List<T> getScrollData(Class<T> entityClass) throws SQLException;
	
	/**
	 * 
	 * getScrollDataByJpql:获取数据 
	 * <br>例子：String jpql = "select k from PActivity k, PActivityType a where k.activityType=a.id and k.id=?1";
	 *	<br>//String hql = "select o from User o where o.id=?1";
	 *	<br>List /<PActivity/> results = EntityDao.getScrollDataByJpql( jpql, new Object[]{1}, 0, 1);
	 * @param entityClass
	 * @param jpql 
	 * @param queryParams
	 * @param firstindex
	 * @param maxresult
	 * @return
	 */
	<T> List<T> getScrollDataByJpql(Class<T> entityClass,String jpql,Object[] queryParams,int firstindex,int maxresult) throws SQLException;
	
	/**
	 * 
	 * getScrollDataByHql:获取数据   
	 * <br>例子：String hql = "select k.id as id ,k.user as user from PActivity k, PActivityType a where k.activityType=a.id and k.id=?";
	 * <br>List<Map<String,Object>> results = EntityDao.getScrollDataByHql(hql, new Object[]{1}, 0, 1);
	 * <br>	for (Map<String,Object> result : results){
	 * <br>	System.out.println("==============================");
	 * <br>	for (String key : result.keySet()){
	 * <br>		System.out.println(key + ":" + result.get(key));
	 * <br>	}
	 * <br>}
	 * @param hql
	 * @param queryParams
	 * @param firstindex
	 * @param maxresult
	 * @return
	 */
	<T> List<Map<String, Object>> getScrollDataByHql(String hql,Object[] queryParams,int firstindex,int maxresult) throws SQLException;
	
	/**
	 * 
	 * getScrollDataBySql:获取数据
	 * <br>例子：select k.id,k.userId from p_activity k, p_activity_type a where k.activityTypeId=a.id and k.id=?"
	 * <br>List<Map<String,Object>> results = EntityDao.getScrollDataBySql(hql, new Object[]{1}, 0, 1);
		<br>for (Map<String,Object> result : results){
		<br>	System.out.println("==============================");
		<br>	for (String key : result.keySet()){
				System.out.println(key + ":" + result.get(key));
		<br>	}
		<br>}
	 * @param sql
	 * @param queryParams
	 * @param firstindex
	 * @param maxresult
	 * @return
	 */
	List<Map<String, Object>> getScrollDataBySql(String sql,Object[] queryParams,int firstindex,int maxresult) throws SQLException;
	
	/**
	 * 
	 * getScrollDataBySql:根据原生sql查询对象
	 * <br>例子：String sql = "select t.* from t_user t where t.id=?0";
	 *	<br>
	 *	<br>List /<TUser/> results = EntityDao.getScrollDataBySql( sql, new Object[]{1}, 0, 1);
	 * @param entityClass
	 * @param jpql
	 * @param queryParams
	 * @param firstindex
	 * @param maxresult
	 * @return
	 * @throws SQLException
	 */
	<T> List<T> getScrollDataBySql(Class<T> entityClass,String jpql,Object[] queryParams,int firstindex,int maxresult) throws SQLException;

	/**
	 * 
	 * save:保存
	 *
	 * @param entity
	 * @return
	 */
	Integer save(Object entity);
	
	/**
	 * 
	 * saveObj:保存
	 *
	 * @param entity
	 * @return
	 */
	Long saveObj(Object entity);
	
	/**
	 * 保存，无返回
	 * @param entity
	 */
	void saveVoid(Object entity);
	/**
	 * 
	 * update:更新
	 *
	 * @param entity
	 * @return
	 */
	boolean update(Object entity);
	
	/**
	 * delete:删除
	 * @param entity
	 * @return
	 */
	void delete(Object entity);
	
	/**
	 * delete:删除
	 * @param entity
	 * @return
	 */
	void deleteDetached(Object entity);
	
	EntityManager getEntityManager();
}

